package com.zhsource.article.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhsource.article.domain.Param;
import com.zhsource.article.mapper.ParamMapper;
import com.zhsource.article.query.ParamQuery;
import com.zhsource.article.service.IParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>@ClassName：ParamServiceImpl
 * <p>@Date 2023/10/17  13:01
 *
 * @Author zzl
 **/
@Service
public class ParamServiceImpl implements IParamService {

    @Autowired
    private ParamMapper paramMapper;

    @Override
    public List<Param> list() {
        return paramMapper.list();
    }

    @Override
    public Param selectById(Long id) {
        return paramMapper.selectById(id);
    }

    @Override
    public PageInfo<Param> page(ParamQuery paramQuery) {
        // 1.下面这句代码表示开启分页，会将紧挨着这句代码的下一次数据库执行进行分页，切记一定要放在要分页的SQL语句前面执行
        PageHelper.startPage(paramQuery.getCurrentPage(), paramQuery.getPageSize());

        // 2.执行SQL语句带条件查询，SQL语句不需要进行分页
        List<Param> page = paramMapper.page(paramQuery);
        // 3.将查询结果转换为PageInfo对象，PageInfo对象中有前端分页所需要的各种参数
        PageInfo<Param> pageInfo = new PageInfo<>(page);
        // 4.响应总条数和分页信息
        return pageInfo;
    }

    @Override
    public void update(Param param) {
        // 1. 修改用户信息
        paramMapper.update(param);
    }
    @Override
    public void insert(Param param) {
        // 1. 新增员工
        paramMapper.insert(param);
    }
    @Override
    public void delete(Long id) {
        paramMapper.delete(id);

    }

    @Override
    public void batchDel(List<Long> ids) {

        paramMapper.batchDel(ids);


    }

    @Override
    public List<Param> getParam() {
        return paramMapper.getParam();
    }

    @Override
    public Map<String, String> getParamMap() {
        List<Param> list = paramMapper.list();
        Map<String, String> paramMap = list.stream().collect(Collectors.toMap(Param::getParamKey, Param::getParamValue));
        return paramMap;
    }
}
